home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / libiconv_src.lha / src / cp936ext.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-07  |  2.5 KB  |  81 lines

  1.  
  2. /*
  3.  * CP936 extensions
  4.  */
  5.  
  6. static const unsigned short cp936ext_2uni_pagea6[181-159] = {
  7.   /* 0xa6 */
  8.                                                           0xfe35,
  9.   0xfe36, 0xfe39, 0xfe3a, 0xfe3f, 0xfe40, 0xfe3d, 0xfe3e, 0xfe41,
  10.   0xfe42, 0xfe43, 0xfe44, 0xfffd, 0xfffd, 0xfe3b, 0xfe3c, 0xfe37,
  11.   0xfe38, 0xfe31, 0xfffd, 0xfe33, 0xfe34,
  12. };
  13. static const unsigned short cp936ext_2uni_pagea8[128-122] = {
  14.   /* 0xa8 */
  15.                   0x0251, 0xfffd, 0x0144, 0x0148, 0xfffd, 0x0261,
  16. };
  17.  
  18. static int
  19. cp936ext_mbtowc (conv_t conv, wchar_t *pwc, const unsigned char *s, int n)
  20. {
  21.   unsigned char c1 = s[0];
  22.   if ((c1 == 0xa6) || (c1 == 0xa8)) {
  23.     if (n >= 2) {
  24.       unsigned char c2 = s[1];
  25.       if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0x80 && c2 < 0xff)) {
  26.         unsigned int i = 190 * (c1 - 0x81) + (c2 - (c2 >= 0x80 ? 0x41 : 0x40));
  27.         unsigned short wc = 0xfffd;
  28.         if (i < 7410) {
  29.           if (i >= 7189 && i < 7211)
  30.             wc = cp936ext_2uni_pagea6[i-7189];
  31.         } else {
  32.           if (i >= 7532 && i < 7538)
  33.             wc = cp936ext_2uni_pagea8[i-7532];
  34.         }
  35.         if (wc != 0xfffd) {
  36.           *pwc = (wchar_t) wc;
  37.           return 2;
  38.         }
  39.       }
  40.       return RET_ILSEQ;
  41.     }
  42.     return RET_TOOFEW(0);
  43.   }
  44.   return RET_ILSEQ;
  45. }
  46.  
  47. static const unsigned short cp936ext_page01[16] = {
  48.   0x0000, 0x0000, 0x0000, 0x0000, 0xa8bd, 0x0000, 0x0000, 0x0000, /*0x40-0x47*/
  49.   0xa8be, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x48-0x4f*/
  50. };
  51. static const unsigned short cp936ext_page02[24] = {
  52.   0x0000, 0xa8bb, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x50-0x57*/
  53.   0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x58-0x5f*/
  54.   0x0000, 0xa8c0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*0x60-0x67*/
  55. };
  56. static const unsigned short cp936ext_pagefe[24] = {
  57.   0x0000, 0xa6f2, 0x0000, 0xa6f4, 0xa6f5, 0xa6e0, 0xa6e1, 0xa6f0, /*0x30-0x37*/
  58.   0xa6f1, 0xa6e2, 0xa6e3, 0xa6ee, 0xa6ef, 0xa6e6, 0xa6e7, 0xa6e4, /*0x38-0x3f*/
  59.   0xa6e5, 0xa6e8, 0xa6e9, 0xa6ea, 0xa6eb, 0x0000, 0x0000, 0x0000, /*0x40-0x47*/
  60. };
  61.  
  62. static int
  63. cp936ext_wctomb (conv_t conv, unsigned char *r, wchar_t wc, int n)
  64. {
  65.   if (n >= 2) {
  66.     unsigned short c = 0;
  67.     if (wc >= 0x0140 && wc < 0x0150)
  68.       c = cp936ext_page01[wc-0x0140];
  69.     else if (wc >= 0x0250 && wc < 0x0268)
  70.       c = cp936ext_page02[wc-0x0250];
  71.     else if (wc >= 0xfe30 && wc < 0xfe48)
  72.       c = cp936ext_pagefe[wc-0xfe30];
  73.     if (c != 0) {
  74.       r[0] = (c >> 8); r[1] = (c & 0xff);
  75.       return 2;
  76.     }
  77.     return RET_ILSEQ;
  78.   }
  79.   return RET_TOOSMALL;
  80. }
  81.